package org.example.Mapper;

import org.apache.ibatis.annotations.*;
import org.example.domain.EmailRecord;

import java.util.Date;

@Mapper
public interface EmailRecordMapper {

    @Delete("DELETE FROM emailRecord WHERE userId=#{userId};")
    void deleteAllEmailRecordsByUserId(Integer userId);//删除学生的所有邮件来往，注销时使用

    @Insert("INSERT INTO emailRecord (userId,askDate,askContent) VALUES (#{userId},#{askDate},#{askContent});")
    void addEmailRecord(Integer userId, Date askDate,String askContent);//用户增加一条邮箱来往

    @Select("SELECT * FROM emailRecord WHERE userId=#{userId} ORDER BY askDate DESC LIMIT #{start},10;")
    EmailRecord[] getEmailRecordsByUserId(Integer userId,Integer start);

    @Select("SELECT * FROM emailRecord WHERE adminId=0 ORDER BY askDate LIMIT #{start},10;")
    EmailRecord[] getEmailRecordsByAdminIdZero(Integer start);

    @Select("SELECT * FROM emailRecord WHERE adminId!=0 ORDER BY answerDate DESC LIMIT #{start},10;")
    EmailRecord[] getEmailRecordsByAdminIdNotZero(Integer start);

    @Update("UPDATE emailRecord SET adminId=#{adminId},answerContent=#{answerContent}," +
            "answerDate=#{answerDate} WHERE id=#{id};")
    void replyEmailRecordById(Integer id,Integer adminId,String answerContent,Date answerDate);

    @Select("SELECT COUNT(id) FROM emailRecord WHERE adminId=0;")
    Integer getNumberByEmailRecordWhereAdminIdEqualZero();
}